import requests
import json
import time
import pandas as pd

# 1.过滤下条记录playTime小于上条记录PlayTime
# 2.重复学习数据createBy修改为repeatStudy
# 3.下条记录结束时间=上条记录结束时间+（下条playTime-上条PlayTime差值）
# 4.当天最大结束时间-最小开始时间大于等于当天max(PlayTime)-min(PlayTime)
# 5.当天同一个学员学习不同视频不存在时间重叠
# 6.删除下条playTime小于等于上条playTime数据


filename = "10.17轨迹数据核对.xlsx"

data = pd.read_excel(io=filename, sheet_name=0, header=1)

# 1.过滤下条记录playTime小于上条记录PlayTime
before_create_time = -1
before_res_code = ''
before_play_time = -1
for i in range(0, len(data)):
    play_time = int(data.iloc[i, 26])
    res_code = str(data.iloc[i, 10])
    if (play_time <= 0 or res_code != before_res_code):
        before_create_time = 0
        before_res_code = res_code
        continue
    if (play_time < before_create_time):
        print('错误行：'+str(i+3) + ' 时间：' + str(before_create_time) + '秒 ->'+str(play_time) +
              '秒 1.过滤下条记录playTime小于上条记录PlayTime')
    before_create_time = play_time


# 3.下条记录结束时间=上条记录结束时间+（下条playTime-上条PlayTime差值）
before_video_end_time = -1
before_res_code = ''
before_play_time = -1
for i in range(0, len(data)):
    play_time = float(data.iloc[i, 26])
    res_code = str(data.iloc[i, 10])
    # video_start_time = time.mktime(time.strptime(
    #     str(data.iloc[i, 21]), "%Y-%m-%d %H:%M:%S"))
    video_end_time = time.mktime(time.strptime(
        str(data.iloc[i, 22]), "%Y-%m-%d %H:%M:%S"))
    # print(str(data.iloc[i, 22]) + ' -> ' + str(data.iloc[i, 23]))
    if (play_time <= 0 or res_code != before_res_code):
        before_video_end_time = video_end_time
        before_res_code = res_code
        before_play_time = play_time
        continue

    play_diff = play_time - before_play_time
    diff = (video_end_time - before_video_end_time)
    # print(str(play_diff) + '->' + str(diff))
    if (play_diff > diff):
        print('错误行：'+str(i+3) + ' 时间：' + str(diff) + '秒 ->'+str(play_diff) +
              '秒 3.下条记录结束时间=上条记录结束时间+（下条playTime-上条PlayTime差值）')
    before_video_end_time = video_end_time
    before_play_time = play_time


# # 4.当天最大结束时间-最小开始时间大于等于当天max(PlayTime)-min(PlayTime)
# before_video_end_time = -1
# before_res_code = ''
# before_play_time = -1
# for i in range(0, len(data)):
#     play_time = float(data.iloc[i, 26])
#     res_code = str(data.iloc[i, 10])
#     # video_start_time = time.mktime(time.strptime(
#     #     str(data.iloc[i, 21]), "%Y-%m-%d %H:%M:%S"))
#     video_end_time = time.mktime(time.strptime(
#         str(data.iloc[i, 22]), "%Y-%m-%d %H:%M:%S"))
#     # print(str(data.iloc[i, 22]) + ' -> ' + str(data.iloc[i, 23]))
#     if (play_time <= 0 or res_code != before_res_code):
#         before_video_end_time = video_end_time
#         before_res_code = res_code
#         before_play_time = play_time
#         continue

#     play_diff = play_time - before_play_time
#     diff = (video_end_time - before_video_end_time)
#     # print(str(play_diff) + '->' + str(diff))
#     if (play_diff > diff):
#         print('错误行：'+str(i+3) + ' 时间：' + str(diff) + '秒 ->'+str(play_diff) +
#               '秒 3.下条记录结束时间=上条记录结束时间+（下条playTime-上条PlayTime差值）')
#     before_video_end_time = video_end_time
#     before_play_time = play_time
